import React, { Component } from 'react'

import './Footer.css'

export default class Footer extends Component {
  deleteDone = () => {
    const { todos } = this.props
    const newTodos = todos.filter(item => !item.done)
    this.props.deleteDone(newTodos)
  }
  handleCheckAll = (event) => {
    this.props.checkAllToDo(event.target.checked)

  }
  render () {
    const { todos } = this.props
    const length = todos.length
    const doneLength = todos.filter(item => item.done).length
    return (
      <div className='todo-footer'>
        <label>
          <input
            type='checkbox'
            checked={doneLength === length && length !== 0}
            onChange={this.handleCheckAll}
          />
        </label>
        <span>
          <span>已完成{doneLength}</span> / 全部{length}
        </span>
        <button className='btn btn-danger' onClick={this.deleteDone}>
          清除已完成任务
        </button>
      </div>
    )
  }
}
